import {
  Column,
  Entity,
  Index,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { BookEntity } from 'src/books/entities/book.entity';

@Index('bookname', ['bookname'], {})
@Index('bookid', ['bookid'], {})
@Entity('book_content', { schema: 'db_book' })
export class TextEntity {
  @PrimaryGeneratedColumn({ type: 'int', name: 'id' })
  id: number;

  @Column('varchar', { name: 'title', length: 255 })
  title: string;

  @Column('varchar', { name: 'bookname', length: 255 })
  bookname: string;

  @Column('longtext', { name: 'content' })
  content: string;

  @Column('int', { name: 'bookid' })
  bookid: number;

  @Column('int', { name: 'bookindex', nullable: true })
  bookindex: number | null;

  @ManyToOne(() => BookEntity, (bookEntity) => bookEntity.bookContents, {
    onDelete: 'RESTRICT',
    onUpdate: 'RESTRICT',
  })
  @JoinColumn([{ name: 'bookid', referencedColumnName: 'bookid' }])
  book: BookEntity;

  @ManyToOne(() => BookEntity, (bookEntity) => bookEntity.bookContents2, {
    onDelete: 'RESTRICT',
    onUpdate: 'RESTRICT',
  })
  @JoinColumn([{ name: 'bookname', referencedColumnName: 'bookname' }])
  bookname2: BookEntity;
}
